<template>
  <j-modal
    :title="title"
    :width="width"
    :visible="visible"
    switchFullscreen
    @ok="handleOk"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
  >
    <tt-collect-flow-form
      ref="realForm"
      @ok="submitCallback"
      :disabled="disableSubmit"
      v-if="lcsz"
    ></tt-collect-flow-form>
    <tt-collect-flow-node-form
      ref="realForm"
      @ok="submitCallback"
      @child-event="parentevent"
      :disabled="disableSubmit"
      v-if="jdsz"
    ></tt-collect-flow-node-form>
  </j-modal>
</template>

<script>
import TtCollectFlowForm from './TtCollectFlowForm'
import TtCollectFlowNodeForm from './TtCollectFlowNodeForm'
export default {
  name: 'TtCollectFlowModal',
  components: {
    TtCollectFlowForm,
    TtCollectFlowNodeForm,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      jdsz: false,
      lcsz: false,
    }
  },
  methods: {
    add(flowcode, tjjb, sortid) {
      console.log(flowcode, tjjb, sortid)
      if (flowcode != null) {
        this.jdsz = true
        this.lcsz = false
      } else {
        this.lcsz = true
        this.jdsz = false
      }
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.add(flowcode, tjjb, sortid)
      })
    },
    edit(record, jdbj) {
      if (jdbj != null) {
        this.jdsz = true
        this.lcsz = false
      } else {
        this.lcsz = true
        this.jdsz = false
      }
      this.visible = true
      this.$nextTick(() => {
        this.$refs.realForm.edit(record)
      })
    },
    close() {
      this.$emit('close')
      this.visible = false
    },
    handleOk() {
      this.$refs.realForm.submitForm()
    },
    submitCallback() {
      this.$emit('ok')
      this.visible = false
    },
    handleCancel() {
      this.close()
    },
    parentevent() {
      this.$emit('child-event', '我是子组件向父组件传递的内容！')
    },
  },
}
</script>
